package com.penghaisoft.microwms.base.web.auth.controller;

import com.penghaisoft.microwms.base.web.auth.service.IRoleResService;
import com.penghaisoft.microwms.common.base.model.BaseResRoleResourceKey;
import com.penghaisoft.microwms.common.controller.BaseController;
import com.penghaisoft.microwms.common.dto.Resp;
import com.penghaisoft.microwms.common.dto.TransResult;
import com.penghaisoft.microwms.common.dto.Transfer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/resroleres")
@Slf4j
public class BaseResRoleResourceController extends BaseController {
	
	@Autowired
	private IRoleResService roleResService;

	/**
	 * 修改角色资源关联信息
	 * 
	 * @param transfer
	 * @return
	 */
	@PostMapping("u")
	public TransResult update(@RequestBody Transfer<String, BaseResRoleResourceKey> transfer) {
		Resp resp = roleResService.updateResRoleRelation(transfer.getConditions(), transfer.getRecords());
		return fromResp(resp);
	}

	/**
	 * 根据角色Id查询角色资源关联信息
	 * 
	 * @param id
	 * @return
	 */
	@GetMapping("r/{id}")
	public TransResult queryByRoleId(@PathVariable String id) {
		System.out.println(id);
		List<BaseResRoleResourceKey> resRoleR = roleResService.queryByRoleId(id);
		return success(resRoleR);
	};

}
